[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Boxing memo's Boxing Word-Wrapped Fields (#2 - exact)
A more difficult but exact way to calculate the number of lines occupied
by a word-wrapped field is to read through a character field word by word,
determining how long each word is, how many words will fit on each line,
how many spaces will be added as a result of word-wrap and, therefore, how
many lines will be required. Because these calculations are complex enough
that you would not want to enter them in a calculated field expression
every time you want to draw a box, we've created three user-defined
functions that will perform the calculations for you. Once you've entered
the functions in your UDF library, you can use them ibn any report. Since
the first function calss the second, which calls the third, you need use
only the first of the UDF's listed below in your calculated field
expression.
. Lines: a UDF that returns the exact numer of lines occupied by the data
of a specified, word-wrapped, character field with a specified field
width
. Tail: a recursive UDF that returns a string consisting of the characters
remaining after line n of a word wrapped field has been processed, with
1 space added to the end of teh string for each line that has been
processed so far.
. Wrapwidth: a recursive UDF that returns the number of characters of the
beginning of its string argument that will print on the next line.
Using these UDFs is much simpler than understanding them, so we'll focus
here on creating and using them (trust us, the expressions work). In
brief, you must add all three user-defined functions to your UDF library.
Then, you must create a calculated field that uses the Lines UDF to return
the number of lines required by the character field you want to box.
To add the UDFs to your UDF library, proceed as follows:
1. Define the Wrapwidth UDF by using the /Field Calculate User-Function
Create command to enter the following declaration:
Wrapwidth(c_data, n_width)
2. When you are prompted, enter the following expression for the Wrapwidth
UDF:
iif(' '$substr(data,1,width),
iif(len(rtrim(data))<=width,len(rtrim(data)),
iif(substr((data,width+1,1)=' ',width,wrapwidth(data,width-1))),width)
Note that R&R will take some time after you press Return to evaluate
this expression.
3. Define the Tail UDF by selecting the create command again and entering
the following declaration:
Tail(c_data,n_width)
4. When prompted, enter the following expression for the Tail UDF:
iif(len(ltrim(data)),tail(substr(ltrim(data),
wrapwidth(ltrim(data),width)+1+' ',width),data)
5. Define the Lines UDF by selecting the Create command again and entering
the following declaration:
Lines(c_data, n_width)
6. When you are prompted, enter the following expression for the Lines
UDF:
len(tail(rtrim(replicate('*',len(DATA)-
len(ltrim(data)))+ltrim(DATA)),WIDTH))
7. Select Quit to exit the User-Function Menu.
To create a calculated field that uses the Lines UDF to calculate the
number of lines occupied by a given word-wrapped character field, proceed
as follows:
1. Select the /Field Calculate Create command.
2. Enter a field name such as LENGTH for the calculated field that will
create the vertical line.
3. Enter an expression such as the following, replacing "Field" with the
name of the character field you want to hox and "Width" with the width
of this field in characters on the report layout:
Lines (Field, Width)
For example, to create a vertical line field for the TITLE field that
has a character width of 50 on the report layout, you should enter the
following expression:
Lines (TITLE,50)
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson